
<template>
  <elm-page-bb class="elm-list-edit">
    <elm-page-tb :splite="false" :splite-show="false">
      <template #top>
        <right>
          <el-button-group>
            <el-button size="mini" @click="add">新增</el-button>
          </el-button-group>
        </right>
      </template>
      <elm-table ref="table" url="/business/hrm/ei/extend/GetData" :post-data="postData" :page-size="9999">
        <el-table-column :label="request.type+'的内容'" align="center">
          <template v-slot="scope">
            <el-input type="textarea" :rows="2" v-model="scope.row.text"></el-input>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="80px" align="center">
          <template v-slot="scope">
            <el-button @click="del(scope.row)"  type="text" size="mini">删除</el-button>
          </template>
        </el-table-column>
      </elm-table>
    </elm-page-tb>
    <template #bottom>
      <el-button type="success" size="small" @click="submit">立即保存</el-button>
      <el-button size="small" @click="close">取消</el-button>
    </template>
  </elm-page-bb>
</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      postData:{type:null,ei_id:null}
    }
  },
  created() {
    this.postData.ei_id=this.request.ei_id;
    this.postData.type=this.request.type;
  },
  methods: {
    add() {
      this.$refs.table.datalist.push({text:null,type:this.request.type,ei_id:this.request.ei_id});
    },
    async del(item)
    {
      if(item.id!=undefined)
      {
        await elm.post("/business/hrm/ei/extend/Delete",{ id: item.id});
      }
      this.$refs.table.datalist = this.$refs.table.datalist.filter(p => !(p==item));
    },
    async submit()
    {
       var ret = await elm.post("/business/hrm/ei/extend/Save",
           {items:this.$refs.table.datalist,ei_id:this.request.ei_id,type:this.request.type});
       if(ret>0)
       {
         this.close();
         this.v("保存成功。");
         this.request.callVue.init_extend(this.request.type);
       }
    }
  }
}
</script>
